# unit_tests.py
# 单元测试：测试用户验证和菜单提取功能
import unittest
from system_code import authenticate_user, get_user_menus

class TestSystemFunctions(unittest.TestCase):
    def test_authenticate_valid_user(self):
        self.assertEqual(authenticate_user("user001", "pw001"), "600")
        self.assertEqual(authenticate_user("user002", "pw002"), "777")

    def test_authenticate_invalid_user(self):
        self.assertIsNone(authenticate_user("user003", "wrongpass"))
        self.assertIsNone(authenticate_user("userXXX", "pw001"))

    def test_get_user_menus(self):
        menus = get_user_menus("777")
        self.assertEqual(len(menus), 3)
        names = [menu["name"] for menu in menus]
        self.assertIn("商品管理", names)
        self.assertIn("供应商管理", names)

if __name__ == '__main__':
    unittest.main()
